//
//  SLSetAccessNameVC.m
//  SlockApp
//
//  Created by 凯朱 on 2024/7/25.
//

#import "SLSetAccessNameVC.h"
#import "SLAccessOneTimeVC.h"
#import "SLAccessDurtionVC.h"
#import "SLFingerCreateVC.h"

@interface SLSetAccessNameVC ()

@end

@implementation SLSetAccessNameVC
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpSubViews];
    
}

-(void)setUpSubViews{
    self.title = kLocalString(@"Make new access");
    _tipLbl.text = kLocalString(@"Make a name for this access");
    [_tf setPlaceholderWithPlaceholderText:kLocalString(@"Make a name for this access") withColor:KColor_placeholdar withFont:kFont(16)];
    if (_isAddFinger) {
        _tipLbl.text = kLocalString(@"Make a name for this fingerprint");
        [_tf setPlaceholderWithPlaceholderText:kLocalString(@"Make a name for this fingerprint") withColor:KColor_placeholdar withFont:kFont(16)];
    }
    _nextBtn.btnStyle = 1;
    [_nextBtn setTitle:kLocalString(@"Next") forState:UIControlStateNormal];
    _tf.textColor = KColor_O;
    _tf.font = kFont(18);
    [_tf showCloseBtn];
    self.bgView.layer.cornerRadius = 20;
    self.bgView.layer.masksToBounds = YES;
}

- (IBAction)nextAction:(id)sender {
    if (_tf.text.length == 0) {
        kShowToast(@"Enter a name");
        return;
    }
    //添加指纹
    if (_isAddFinger) {
        SLFingerCreateVC *vc = [[SLFingerCreateVC alloc] init];
        _fingerModel.fingName = _tf.text;
        vc.fingerModel = _fingerModel;
        vc.isAddFinger = _isAddFinger;
        vc.keyModel = _keyModel;
        [self.navigationController pushViewController:vc animated:YES];
        return;
    }
    
    //添加钥匙
    //蓝牙钥匙
    _keyModel.keyName = _tf.text;
    if (_keyModel.keyType == 1) {
        if (_keyModel.lockType == 1) {
            SLFingerCreateVC *vc = [[SLFingerCreateVC alloc] init];
            vc.keyModel = _keyModel;
            [self.navigationController pushViewController:vc animated:YES];
        }else{
            [ZCTool uploadBlueToothKeyData:_keyModel];
        }
        return;
    }
    //指纹钥匙
    if (_keyModel.keyType == 2) {
        SLAccessDurtionVC *vc = [[SLAccessDurtionVC alloc] init];
        vc.keyModel = _keyModel;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else if (_keyModel.keyType == 1 || _keyModel.keyType == 3){
        SLAccessOneTimeVC *vc = [[SLAccessOneTimeVC alloc] init];
        vc.keyModel = _keyModel;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


@end
